/**
 * @(#) TotalIncomProxy.as
 *
 * @date		2009. 04. 23.
 * @version		1.0
 * @author		Jo,Chang Hun
 * @description	 연말정산  - Proxy
 * 				특별공제 보험료 입력 관리 
 */
package com.skt.common_hr.yearadjustment.model
{
	
	import com.skt.common_hr.common.puremvc.CommonProxy;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	

	public class DomainProxy extends CommonProxy
	{
		public static const NAME:String = "DomainProxy";

		public static const LOAD_DOMAIN_LIST_COMPLETE:String = "loadDomainListComplete";
		public static const LOAD_DOMAIN_LIST_FAILED:String = "loadDomainListFailed";
		
		public static const PKR_MEPCD:String = "PKR_MEPCD";
		
		public var msgStr:String;
		public var current_domain:String = "";
		public var codeList:ArrayCollection = new ArrayCollection();
		

		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function DomainProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function loadCodeList(type:String):void
		{
			var param:Object = new Object();
			param["I_DNAME"] = current_domain = type;
			loadData("Z_HR_0003", param, result, fault); 
		}
		

		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(retCode==0) {  
				codeList = parseCodeList(event.result.ITAB);
				facade.sendNotification(LOAD_DOMAIN_LIST_COMPLETE, this);
			}
			else {
				msgStr = event.result["RETTEXT"];
				facade.sendNotification(LOAD_DOMAIN_LIST_FAILED, this);
			}
		}
		
		//관계 콤보박스 조회 실패
		private function fault(event:FaultEvent):void
		{
			msgStr = event.fault.faultString;
			facade.sendNotification(LOAD_DOMAIN_LIST_FAILED, this);
		}
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 연말정산  MainList Value Object
		 */
		/**
		 * 개인정보
		 * 
		 * @param
		 * @return 특별공제 보험료 Value Object
		 */
		private function parseCodeList(arr:ArrayCollection):ArrayCollection
		{
			var returnArr:ArrayCollection = new ArrayCollection();
			for each(var reg:Object in arr){
				var vo:Object = new Object();
				
				vo.CODE	= reg["CODE"];
				vo.TEXT	= reg["TEXT"];
				
				returnArr.addItem(vo);
			}
			return returnArr;
		}
		
	}
}